﻿Imports System.Data.OleDb

Public Class EditHanhKhach
    Inherits DataProvider

    Public Function Check(ByVal cmnd As String) As Boolean
        Dim sql As String = "SELECT * FROM HanhKhach WHERE CMND='" + cmnd + "'"
        If GetDT(sql).Tables(0).Rows.Count() = 0 Then
            Return True
        End If
        Return False
    End Function

    Public Function save(ByVal dtohanhkhach As DTO.EditHanhKhach) As Integer
        Dim sqo As String = "UPDATE HanhKhach SET HoTen='" + dtohanhkhach.hoten + "',DienThoai='" + dtohanhkhach.dienthoai.ToString + "',CMND='" + dtohanhkhach.cmnd.ToString + "' WHERE ID=" + dtohanhkhach.mahk.ToString
        Return Me.SaveData(sqo)
    End Function

    Public Function dtload(ByVal mahk As Integer) As DataSet
        Dim sql As String = "SELECT * FROM HanhKhach WHERE ID=" + mahk.ToString
        Return GetDT(sql)
    End Function

    Public Function lay_thong_tin_hanh_khach(ByVal cmnd) As DTO.EditHanhKhach
        Dim hanhkhach As New DTO.EditHanhKhach
        Dim sql_query As String = "SELECT * from hanhkhach where cmnd = '" + cmnd + "'"

        Dim reader = Me.GetData(sql_query)
        If (IsNothing(reader)) Then
            Return Nothing
        End If

        reader.Read()
        hanhkhach.cmnd = reader.Item("CMND")
        hanhkhach.dienthoai = reader.Item("DienThoai")
        hanhkhach.hoten = reader.Item("HoTen")
        hanhkhach.mahk = reader.Item("id")
        Me.cnn.Close()
        Return (hanhkhach)
    End Function

End Class
